/****************************************************
          File Name:15-1.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun Jan 11 04:18:42 2015
*****************************************************/

#ifndef HEAD_H_
#define HEAD_H_
#include <iostream>

class Remote; // can NOT without this declare !!
class Tv
{
    private:
        int state;
        int volume;
        int maxchannel;
        int channel;
        int mode;
        int input;
    public:
        friend class Remote;
        enum State {Off, On};
        enum {Minval, Maxval = 20};
        enum {Antenna, Cable};
        enum { TV, DVD };

        Tv(int s = Off, int mc = 125) : state(s), volume(5),
        maxchannel(mc), channel(2), mode(Cable), input(TV) {}
        void onoff() { state = (state == On) ? Off : On; }
        bool ison() const { return state == On; }
        bool volup();
        bool voldown();
        void chanup();
        void chandown();
        void set_mode() { mode = (mode == Antenna) ? Cable : Antenna; }
        void set_input() { input = (input == TV) ? DVD : TV; }
        void settings() const;
        void switch_mode(Remote & r);
};

class Remote
{
    private:
        int mode;
        int pmode; // play mode: 1=ormal mode, 0=inter mode
    public:
        friend class Tv;
        enum State {Off, On};
        enum {Minval, Maxval = 20};
        enum {Antenna, Cable};
        enum {TV, DVD};

        Remote(int m = TV) : mode(m), pmode(1)  { }
        bool volup(Tv & t) { return t.volup(); };
        bool voldown(Tv & t) { return t.voldown(); };
        void onoff(Tv & t) { t.onoff(); };
        void chanup(Tv & t) { t.chanup(); };
        void chandown(Tv & t) { t.chandown(); };
        void set_mode(Tv & t) { t.set_mode(); };
        void set_input(Tv & t) { t.set_input(); };
        void set_chan(Tv & t, int c) { t.channel = c; };
        void show()
		{
			using std::cout;
			pmode == true ? cout << "normal mode\n" : cout << "inter mode\n";
		}
};

inline void Tv::switch_mode(Remote & r)
{
    if(ison())
        r.pmode = (r.pmode == 1) ? 0 : 1;
}

#endif